package de.tum.in.eist.im.shared.ChatChannel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import de.tum.in.eist.im.shared.User.User;

@SuppressWarnings("serial")
public class ChatChannel implements Serializable {
	
	// private variables
	private Long chatId = null;
	private String title = null;
	private List<User> activeUserInChatChannel =  new ArrayList<User>();
	
	/**
	 * default constructor
	 */
	public ChatChannel() {}
	
	/**
	 * constructor creating a ChatChannel object
	 * @param chatId the id of the chat channel
	 * @param title the title of the chat channel
	 */
	public ChatChannel(Long chatId, String title) {
		this.chatId = chatId;
		this.title = title;
	}
	
	/**
	 * return the id of the chat channel
	 * @return the id of the chat channel
	 */
	public Long getChatId() {
		return this.chatId;
	}
	
	/**
	 * return the title of the chat channel
	 * @return the title of the chat channel
	 */
	public String getTitle() {
		return this.title;
	}
	
	/**
	 * add a user to the chat channel
	 * @param user
	 */
	public void addUserToChatChannel(User user) {
		boolean found = false;
		for (User aU : activeUserInChatChannel) {
			if (aU.getUsername().equals(user.getUsername()))
				found = true;
		}
		
		if (!found)
			activeUserInChatChannel.add(user);
		
	}
	
	/**
	 * TODO: remove a user of the chat channel
	 */
	
	/**
	 * return the list of user in the current channel
	 * @return List of User in the current channel
	 */
	public List<User> getUserInChannel() {
		return activeUserInChatChannel;
	}
	
	/**
	 * deletes a user of the chat channel
	 * @param u
	 */
	public void removeUserFromChatChannel(User user) {
		User deleteUser = null;
		for (User u : activeUserInChatChannel) {
			if (u.getUsername().equals(user.getUsername())) {
				deleteUser = u;
			}
		}
		if (null != deleteUser)
			activeUserInChatChannel.remove(deleteUser);
	}
}
